package component.fulltextsearch.util;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;


public class SearchConfigUtil {
	private static SearchConfigUtil instance = null;
	private static final String NAME = "fulltextsearch";	
	private Properties prop;
	
	private Properties handlingsProp;

	private SearchConfigUtil() {
		try {
			prop = PropertiesUtil.getInstance().getProperties(NAME);
		} catch (FileNotFoundException e) {
			System.err.println("没有找到fulltextsearch.properties配置文件");
			e.printStackTrace();			
		}		
	}

	public static SearchConfigUtil getInstance() {
		if (instance == null) {
			instance = new SearchConfigUtil();
		}
		return instance;
	}
	
	public Properties getHandlingProperties() {		
		if (handlingsProp == null) {
			handlingsProp = new Properties();
			Set keySet = prop.keySet();
			for (Iterator it = keySet.iterator(); it.hasNext();) {
				String key = (String) it.next();
				if (key.startsWith("handling.")){
					String newKey = key.substring("handling.".length());
					String value = prop.getProperty(key);
					handlingsProp.put(newKey, value);
				}		
			}
		}		
		return handlingsProp;
	}

	public String getProperty(String key) {
		return prop.getProperty(key);
	}

	public String getProperty(String key, String defaultValue) {
		return prop.getProperty(key, defaultValue);
	}
	
	public static String getIndexdir(){
		String indexdir = getInstance().getProperty("indexdir");
		return indexdir;
	}
	
	public static String getBusUrl(){
		String busUrl = getInstance().getProperty("url");
		return busUrl;
	}
	
	//一次性删除索引的最大记录数
	public static int getMaxDeleteIndex(){
		return 1000;
	}
	
	public static String getSearchUrl(){
		return "/component/fulltextsearch";
	}
	
	public static String getSearchPath(){
		return "/component/fulltextsearch";
	}
	
	public static String getJs(){
		return "";
	}
	
	public static String getSimpleCss(){
		return getSearchPath() + "/simple.css";
	}
	
	public static String getAdvanceCss(){
		return getSearchPath() + "/advance.css";
	}
}
